﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESOL.Common;
using ESOL.Business.Sec;

namespace ESOL.WinUI.Sec
{
    public partial class frmChangePassword : BaseForm.frmBaseDialogyMaintainForm
    {
        public frmChangePassword()
        {
            InitializeComponent();
        }

        private void frmChangePassword_Load(object sender, EventArgs e)
        {
            txtUserAccount.Text = CommonParameter.CurrentUser.UserAccount;
            txtFullName.Text = CommonParameter.CurrentUser.ChineseName;
        }

        protected override void Click_Save()
        {
            if (string.IsNullOrEmpty(txtOldPassword.Text))
            {
                MessageBox.Show("请输入旧密码！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtOldPassword.Text != CommonParameter.CurrentUser.Password && Encryption.Encrypt(txtOldPassword.Text) != CommonParameter.CurrentUser.Password)
            {
                MessageBox.Show("密码错误！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (string.IsNullOrEmpty(txtNewPassword.Text))
            {
                MessageBox.Show("请输入新密码！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtNewPassword.Text != txtConfirmPassword.Text)
            {
                MessageBox.Show("第一次输入的新密码和第二次输入的不匹配！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (SecUserBs.SavePassword(CommonParameter.CurrentUser, txtNewPassword.Text))
            {
                this.DialogResult = DialogResult.OK;
            }
        }

    }
}
